﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using RearLivestock.Common.Domains.hhx;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Dtos;
using RearLivestock.Common.Infrastructure.Interface;
using RearLivestock.RBAC.ErrorCodeEnum;

namespace RearLivestock.RBAC.Api.Application.hqApplication.Commands.Bedroomss
{
    public class GetBedroomTypesHander : IRequestHandler<GetBedroomTypesCommand, Result>
    {
        private readonly IBaseRepository<BedroomTypes> bedroomTypesRepository;

        public GetBedroomTypesHander(IBaseRepository<BedroomTypes> bedroomTypesRepository)
        {
            this.bedroomTypesRepository = bedroomTypesRepository;
        }



        public async Task<Result> Handle(GetBedroomTypesCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var res = await (await bedroomTypesRepository.GetAll()).ToListAsync();
                if (res != null)
                {
                    result.Data = res;
                    result.Code = (int)CommonErrorCode.Success;
                }
            }
            catch (Exception)
            {
                result.Msg = "列表获取异常";
            }
            return result;
        }
    }
}
